﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace BaoJian.eshop.mn
{
    public partial class preferenceAddressMgrApp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (HttpContext.Current.Request.QueryString["returl"] != null)
                {
                    HttpContext.Current.Response.Redirect(@"~/login.aspx?returl=" + Server.UrlEncode(HttpContext.Current.Request.QueryString["returl"]));
                }
                else
                {
                    HttpContext.Current.Response.Redirect(@"~/login.aspx?returl=" + Server.UrlEncode(@"/e/mn/preferenceAddressMgrApp.aspx"));
                }
            }

            if (!Page.IsPostBack)
            {
                LYQ.BLL.GuestAddress bll = new LYQ.BLL.GuestAddress();
                //先看看是否有删除的操作
                if (HttpContext.Current.Request.QueryString["action"] != null)
                {
                    if (HttpContext.Current.Request.QueryString["action"] == "delete")
                    {
                        string sid = HttpContext.Current.Request.QueryString["sid"];
                        bll.Delete(Convert.ToInt32(sid));
                    }
                }
             
                DataSet ds = bll.GetList("UID='" + HttpContext.Current.User.Identity.Name + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    OrderAddAddressTitle.Visible = true;
                    OrderAddressList.Visible = true;
                    DataList1.DataSource = ds.Tables[0].DefaultView;
                    DataList1.DataBind();
                }

            }
            else  
            {
                //
                if (HttpContext.Current.Request.Form["name1"] != "")
                {
                    LYQ.BLL.GuestAddress bll = new LYQ.BLL.GuestAddress();
                    LYQ.Model.GuestAddress model = new LYQ.Model.GuestAddress();
                    model.SID = Tools.Common.GetMaxSIDAddedONE("GuestAddress");
                    model.UID = HttpContext.Current.User.Identity.Name;
                    model.Name = HttpContext.Current.Request.Form["name1"];
                    model.ProviceName = HttpContext.Current.Request.Form["province_name"];
                    model.CityName = HttpContext.Current.Request.Form["city_name"];
                    model.AreaName = HttpContext.Current.Request.Form["district"];

                    model.Address = HttpContext.Current.Request.Form["addressLine11"];
                    model.Provice = HttpContext.Current.Request.Form["province_name"];
                    model.City = HttpContext.Current.Request.Form["city_name"];
                    model.Area = HttpContext.Current.Request.Form["district"];
                    model.PostalNUM = HttpContext.Current.Request.Form["postcode1"];
                    model.Tel = HttpContext.Current.Request.Form["phone1"];
                    model.EMail = HttpContext.Current.Request.Form["email1"];
                    bll.Add(model);

                    HttpContext.Current.Response.Redirect("orderCfmApp.aspx?a="+model.SID);
                }                
            }
        }


    }
}
